/*
 * Copyright (c) 2012,东方口岸科技有限公司
 * All rights reserved.
 * 文件名称：SequenceService.java
 * 摘    要：
 * 版本：1.0
 * 作    者：fengzhiyong
 */
package com.cneport.transfer.router.support.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cneport.transfer.router.support.mapper.SequenceMapper;
import com.cneport.transfer.util.DateUtil;


/**
 *@CreateDate:2012-7-12
 *@Description:序列号服务
 */
@Component
public class SequenceService {

    @Autowired
    private SequenceMapper sequenceMapper;
    
    public String getSequence(String sequenceName){
        long sequenceCount=sequenceMapper.getSequence(sequenceName);
        String sequenceId=getSequenceID(sequenceName,sequenceCount);
        sequenceMapper.updateSequence(sequenceName);
        return sequenceId;
    }
    
    private  String getSequenceID(String sequenceName,long sequenceCount) {
        String sequenceId ="";
        Date date = new Date();
        String date14String = DateUtil.convertDateToYYYYMMddHHmmSS(date);    
        String sequences=sequenceCount+"";
        int num=18-sequences.length();
        for(int i=0;i<num;i++){
            sequenceId+="0"; 
        }
        sequenceId=date14String+sequenceId+sequences;
        return sequenceId;
    }
}
